package com.example.demo.controller;

import com.example.demo.config.ResponseBean;
import com.example.demo.config.ResponseMessage;
import com.example.demo.form.QueryStudentForm;
import com.example.demo.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author BleethNie
 * @version 1.0
 * @date 2020-07-31 9:17
 **/

@RestController
@RequestMapping("/student/info")
@Api(tags = "后台管理--学生管理")
@Slf4j
public class StudentController {

    @Autowired
    private StudentService studentService;

    @ApiOperation("01 查看学生信息列表(完成)")
    @GetMapping(value = "/student-list")

    public ResponseEntity<ResponseBean> listStudent() {
        ResponseBean response = studentService.listStudent();
        return ResponseEntity.status(response.getStatus()).body(response);
    }

    @ApiOperation("02 分页查询学生信息(完成)")
    @GetMapping(value = "/student-page")
    public ResponseEntity<ResponseBean> listStuInfo(QueryStudentForm form ) {
        ResponseBean response = studentService.listStuInfo(form);
        return ResponseEntity.status(response.getStatus()).body(response);
    }

    @ApiOperation("03 添加学生信息(完成)")
    @PostMapping(value = "/student-add")

    public ResponseEntity<ResponseMessage> addStuInfo() {
        ResponseMessage response = studentService.addStu();
        return ResponseEntity.status(response.getStatus()).body(response);
    }


    @ApiOperation("04 修改学生信息(完成)")
    @PostMapping(value = "/student-edit")
    public ResponseEntity<ResponseMessage> editStuInfo(Integer id) {
        ResponseMessage response = studentService.editStuInfo(id);
        return ResponseEntity.status(response.getStatus()).body(response);
    }
}
